package com.lancer.fileOperate.xml.sax;

import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.io.*;
import java.util.List;

public class ConfigUtil {

    public static void main(String[] args) throws IOException, SAXException, ParserConfigurationException {
        parseXmlFile();
    }


    public static  List<ServiceBean>  parseXmlFile() throws ParserConfigurationException, SAXException, IOException {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser parser = factory.newSAXParser();
        ServiceHandle serviceHandle = new ServiceHandle();
        //开始解析
        InputStream resourceAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.xml");
        parser.parse(resourceAsStream,serviceHandle);
        List<ServiceBean> services = serviceHandle.getServices();

        return services;
    }
}
